/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lx_easyfinace.mytable;

import java.awt.Color;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Administrator
 */
public class MyTableModel extends AbstractTableModel {

    private static final long serialVersionUID = 1L;
    //创建表示各个列类型的类型数组
    Class[] typeArray = {Object.class, Double.class, Boolean.class, Icon.class, Color.class};
    //创建列标题字符串数组
    String[] head = {"Object", "Number", "Boolean", "Icon", "Color"};
    //创建初始表格数据
    Object[][] data = {{"这里是字符串1", new Integer(20), new Boolean(true),
            new ImageIcon("D:/p1.gif "), Color.black},
        {"这里是字符串2", new Double(12.34), new Boolean(false),
            new ImageIcon("D:/p2.gif "), Color.darkGray},
        {"这里是字符串3", new Integer(125), new Boolean(true),
            new ImageIcon("D:/p3.gif"), Color.white}};
    //重写getColumnCount方法

    public int getColumnCount() {
        return head.length;
    }
    //重写getRowCount方法   

    public int getRowCount() {
        return data.length;
    }
    //重写getColumnName方法

    public String getColumnName(int col) {
        return head[col];
    }
    //重写getValueAt方法

    public Object getValueAt(int r, int c) {
        return data[r][c];
    }
    //重写getColumnClass方法

    public Class getColumnClass(int c) {
        return typeArray[c];
    }
    //重写isCellEditable方法

    public boolean isCellEditable(int r, int c) {
        return true;
    }
    //重写setValueAt方法

    public void setValueAt(Object value, int r, int c) {
        data[r][c] = value;
        //
        this.fireTableCellUpdated(r, c);
    }
}
